import {
  Controller,
  Get,
  Post,
  Body,
  Request,
  UseGuards,
} from '@nestjs/common';
import { MailerService } from './mailer.service';
import { AuthGuard } from '@nestjs/passport';
import { Mail } from './mail.dto';
@Controller('mail-center')
export class MailerController {
  constructor(private mailerService: MailerService) {}
  @Post('send')
  @UseGuards(AuthGuard('jwt'))
  sendMail(@Body() mail: Mail, @Request() req) {
    return this.mailerService.sendMail(mail, req);
  }

  @Get('outbox')
  @UseGuards(AuthGuard('jwt'))
  findOutbox(@Request() req) {
    return this.mailerService.findOutbox(req);
  }

  @Get('inbox')
  @UseGuards(AuthGuard('jwt'))
  findInbox(@Request() req) {
    return this.mailerService.findInbox(req);
  }
  @Post('receive')
  @UseGuards(AuthGuard('jwt'))
  receiveMail(@Body('accountId') accountId: number, @Request() req) {
    console.log(accountId);
    return this.mailerService.receiveMail(req.user.id, accountId);
  }
}
